<template>
  <div class="page-login">
    <div class="container">
      <div class="page-login-title">{{ $t('login.title') }}</div>
      <div class="form-wrap">
        <img class="page-login-logo" src="../../assets/login_images/bg_shape.png"><img>
        <div class="wrap-input">
          <el-form ref="loginForm" :model="loginForm" class="form-horizontal login-form">
            <span class="heading">{{ $t('login.logIn') }}</span>
            <div class="form-group">
              <el-input v-model="loginForm.user_name" :placeholder="$t('login.inputUserName')" type="text" @keydown="onKeyDown" />
            </div>
            <div class="form-group help">
              <el-input v-model="loginForm.password" :placeholder="$t('login.inputPassword')" type="password" @keydown="onKeyDown" />
            </div>
            <div class="form-group help">
              <el-button class="btn btn-block login-btn" @click.native.prevent="login()">{{ $t('login.logIn') }}</el-button>
            </div>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
var md5 = require('md5.js')
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        // user_name: '15138247228',
        // password: 'e10adc3949ba59abbe56e057f20f883e',
        user_name: '',
        password: '',
        school_sn: 'BBBBBB'
      }
    }
  },
  methods: {
    // 回车登录
    onKeyDown() {
      if (event.keyCode === 13) {
        event.returnValue = false
        this.login()
      }
    },
    // 登录
    login() {
      const md5Password = new md5().update(this.loginForm.password).digest('hex')
      this.loginForm.password = md5Password
      this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
        this.$router.push({ path: this.redirect || '/' })
      })
    }
  }
}
</script>

<style scoped>
  .page-login {
    background: url(../../assets/login_images/bg_one.png);
    width: 100vw;
    min-height: 100vh;
  }
  .container {
    width: 100%;
    margin: 0 auto;
    padding-right: 15px;
    padding-left: 15px;
  }
  .page-login-title {
    text-align: center;
    color: #ffffff;
    font-size: 4.6rem;
    letter-spacing: 20px;
    padding-top: 5%;
    margin-left: 20px;
  }
  .form-wrap {
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  .form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
  }
  .btn {
    display: inline-block;
    padding: 6px 12px;
    margin-bottom: 0;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.42857143;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    background-image: none;
    border: 1px solid transparent;
    border-radius: 4px;
  }
  .btn-block {
    display: block;
    width: 100%;
  }
  .login-btn {
    padding: 4.5% !important;
    border-radius: 100px;
    background-color: #247ac5;
    border-color: #247ac5;
    font-size: 18px;
    color: #fff;
    letter-spacing: 30px;
    text-indent: 30px;
    outline: none;
  }
  /* 登陆页图标 */
  .page-login-logo {
    margin-top: 6%;
    width: 44%;
    text-align: right;
    margin-right: 6%;
    display: none;
  }
  /* 登陆页表单 */
  .wrap-input {
    width: 27%;
    height: 47%;
    padding: 20px;
    margin-right: 260px;
    margin-top: 138px;
    margin-right: 14%;
    margin-top: 6%;
  }
  .form-horizontal {
    background: #fbfcfe;
    padding-bottom: 20px;
    border-radius: 15px;
    text-align: center;
    -webkit-box-shadow: 0px 1px 8px 0.6px #2e7de4;
    -moz-box-shadow: 0px 1px 8px 0.6px #2e7de4;
    box-shadow: 0px 1px 8px 0.6px #2e7de4;
  }
  .form-horizontal .heading {
    display: block;
    font-size: 36px;
    padding: 36px 0 36px 0;
    color: #247ac5;
  }
  .form-horizontal .form-group {
    padding: 0 8%;
    margin: 0 0 8% 0;
    position: relative;
  }
  .form-horizontal .form-control {
    background: #f0f0f0;
    border: none;
    box-shadow: none;
    padding: 8% 20px 8% 13%;
    transition: all 0.3s ease 0s;
    border-radius: 100px;
    outline: none;
  }
  /deep/ .form-group .el-input__inner {
    background: #f0f0f0;
    border: none;
    box-shadow: none;
    padding: 8% 20px 8% 13%;
    transition: all 0.3s ease 0s;
    border-radius: 100px;
    outline: none;
  }
  .form-horizontal .form-control:focus {
    background: #e0e0e0;
  }
  @media screen and (min-width: 375px) {
    .page-login {
      padding-bottom: 50px;
      box-sizing: border-box;
    }
    .page-login-title {
      padding-top: 20%;
    }
    .page-login-logo {
      display: none;
    }
    .wrap-input {
      width: 100%;
      margin-right: 0;
      margin-top: 14%;
    }
  }
  @media screen and (min-width: 667px) {
    .page-login-title {
      padding-top: 5%;
    }
    .page-login-logo {
      margin-right: 3%;
      margin-top: 0;
      display: block;
    }
    .wrap-input {
      width: 50%;
      margin-right: 0;
      margin-top: 6%;
    }
  }
  @media screen and (min-width: 1024px) {
    .page-login-logo {
      margin-top: 6%;
      width: 38%;
      margin-right: 10%;
    }
    .wrap-input {
      width: 30%;
      padding: 20px;
      margin-right: 13%;
      margin-top: 6%;
    }
  }
  @media screen and (min-width: 1366px) {
    .wrap-input {
      width: 24%;
      margin-right: 16%;
    }
    .page-login-title {
      padding-top: 4%;
      font-size: 5.4rem;
    }
  }
</style>
